import { Component, OnInit } from '@angular/core';
import { EventService } from '../services/event.service';
import { RequestReplyService } from '../services/request-reply.service';
import { BookedService } from '../services/booked.service';
import { Utils } from '../common/Common';

@Component({
  selector: 'app-banner',
  templateUrl: './banner.component.html',
  styleUrls: ['./banner.component.scss']
})
export class BannerComponent implements OnInit {

  booked: any;
  delay: number ;
  hhmmss: string;

  hh: string;
  mm: string;
  ss: string;

  constructor(
    private eventService: EventService,
    private requestService: RequestReplyService,
    private bookedService: BookedService,

  ) { }

  ngOnInit() {
  }

  exit() {
    this.eventService.sendExit();
  }

  getNickName() {
    const me = this.requestService.LoadMe();
    return me && me.nickName;
  }

  getName() {
    const me = this.requestService.LoadMe();
    return me && me.uin;
  }

  getBooked() {
    const bw = this.bookedService.bookedWrapper;
    if (!bw) {
      return null;
    }

    this.delay = bw.delay;
    this.hhmmss = Utils.MillsToHHMMSS(this.delay);
    const hms = this.hhmmss.split(':');
    this.hh = hms[0];
    this.mm = hms[1];
    this.ss = hms[2];

    if (bw.current) {
        this.booked = bw.current;
        return  {title: 'Current', booked: bw.current };
      } else if (bw.next) {
        this.booked = bw.next;
        return  {title: 'Next', booked: bw.next };
      }


  }

}
